package com.stlm2.controller;

import com.stlm2.core.common.page.PageView;
import com.stlm2.dems.entity.*;
import com.stlm2.dems.service.CardsService;
import com.stlm2.dems.service.UserCardsService;
import com.stlm2.dems.service.UserService;
import com.stlm2.util.StringUtils;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Author：fuchunyu
 * Date：2017/10/13
 * Description：卡券控制器
 */
@Controller
@RequestMapping("/cardsC")
public class CardsController {
    @Resource
    private UserService userService;
    @Resource
    private CardsService cardsService;
    @Resource
    private UserCardsService userCardsService;

    //领券中心
    @ResponseBody
    @RequestMapping(value = "/searchCards.json",produces = "application/json;charset=UTF-8")
    public String searchCards(String companyCode,ModelMap model, String page,String token){
        User user=userService.getByToken(token);
        PageView pageview =new  PageView();
        int pageNo = 1;
        int pageSize=20;
        if (NumberUtils.isDigits(page) && !"0".equals(page.trim())) {
            pageNo = NumberUtils.toInt(page);
        }
        Cards cards =new Cards();
        cards.setCardsState(1);
        pageview= cardsService.getPage(pageNo,pageSize,cards);
        if (pageview!=null){
            model.put("data",cardsService.convert(pageview.getRecords(),user));
            model.put("recordsTotal", pageview.getRowCount());
            model.put("totalPage", pageview.getPageCount());
        }
        model.put("pageNo", page);
        return CodeContent.returnSuccess(model);
    }




}
